{% include 'JDXJ/JDXJ_index.html' %}

<div class="am-cf admin-main">
  {% include 'sidebar.html' %}
  <!-- content start -->
  <div class="admin-content">
    <div class="admin-content-body">
      <div class="am-cf am-padding">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">基础数据</strong></div>
      </div>
      <div class="am-g" style="position: absolute;height: 100%;right: 0px;left: 260px;width: auto;">

        {% include 'JDXJ/JCSJ/JDXJ_JCSJ_SIDEBAR.html' %}

        <div class="am-u-sm-10" style="position: absolute;width:auto;right:0;left: 200px;height:85%;overflow-y: scroll;">
          <div class="am-u-sm-12 am-u-md-6">
            <div class="am-btn-toolbar">
              <div class="am-btn-group am-btn-group-xs">
                <button style="margin: 0 5px" type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="back_to()">返回</button>
                <button style="margin: 0 5px" disabled="true" id="add_save" type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="add_save()"><span class="am-icon-plus"></span>保存</button>
                <button style="margin: 0 5px" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="delect_all()"><span class="am-icon-trash-o"></span> 删除</button>
              </div>
            </div>
          </div>

          <div class="am-u-sm-12 am-u-md-12 " id="div_bxd" style="background-color: #FFFFFF;margin: 1px auto;padding: 20px;">

            <div class="am-form-group">

              <div class="am-g am-margin-top am-form-group">

                <div class="div_text am-text-right">系统名称：</div>
                <div class="am-u-md-3 am-u-end" style="padding-left: 0px;">
                  <span>{{  sysname  }}</span>

                </div>
                <div class="div_text am-text-right">设备类型：</div>
                <div class="am-u-md-3 am-u-end" style="padding-left: 0px;">
                  <div class="am-btn-group" id="position_div">
                      <span id="deviceName">{{  devicename  }}</span>
                  </div>
                </div>
              </div>

            </div>

            <div class="am-form-group">
              <div class="am-g am-margin-top am-form-group">
                <div class="div_text am-text-right">地理位置：</div>
                <div class="am-u-md-3 am-u-end" style="padding-left: 0px;">
                <!--   <select id='parts_sub_id' name='parts_sub_id' class="input_width" onchange="parts_sub_change()"> -->
                  <select id='parts_sub_id' name='parts_sub_id' class="input_width">                  
                    {% for i in LocationInfo %}
                    <option value={{ i.locationid }}>{{ i.locationname }}</option>
                    {% endfor %}
                  </select>
                </div>
                <div class="div_text am-text-right">起始编号：</div>
                <div class="am-u-md-3 am-u-end" style="padding-left: 0px;">
                  <input type="number" placeholder="整数" name="" id="parameter1" class="input_width" >
                </div>
              </div>
            </div>
            <div class="am-form-group">

              <div class="am-g am-margin-top am-form-group">
                <div class="div_text am-text-right">终止编号：</div>
                <div class="am-u-md-3 am-u-end" style="padding-left: 0px;">
                  <input type="number" placeholder="整数" name="" id="parameter2" class="input_width" >
                </div>
                <div class="am-u-md-4 am-u-end" style="padding-left: 0px;">
                  <button style="float: right;" type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="add_number()" id="button_number" value="1">生成编号</button>
                </div>

              </div>
            </div>
   
            <table id="grid" class="am-table am-table-striped am-table-hover table-main am-table-compact am-text-nowrap">
              <thead>
                <tr>
                  <th class="table-title">序号</th>
                  <th class="table-title">编号</th>
                  <th class="table-title">地理位置</th>
                  <th class="table-title">设备名称</th>
                  <th class="table-title">删除</th>
                </tr>
              </thead>
              <tbody id="tbody_add">

              </tbody>
            </table>

          </div>



        </div>

      </div>
    </div>
  </div>
</div>
{% include 'footer.html' %}
<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="assets/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="/static/assets/js/jquery.min.js"></script>
<!--<![endif]-->
<script src="/static/assets/js/amazeui.min.js"></script>
<script src="/static/assets/js/amazeui.tree.js"></script>
<script type="text/javascript" src="/static/assets/js//layer.js"></script>
<script src="/static/assets/datatables/amazeui.datatables.min.js"></script>
<script src="/static/assets/dialog/amazeui.dialog.min.js"></script>
<link rel="stylesheet" type="text/css" href="/static/assets/css/amazeui.tree.css" />
<script src="/static/assets/js/app.js"></script>
<style type="text/css">
  .li_a {
    color: #5c5c5c;
  }
  .input_width {
        width: 90%;
      }

      
      .div_text {
        width: 20%;
        padding-right: 1.5rem;
        float: left;
        position: relative;
      }
</style>
<script type="text/javascript">
  $("#collapse-nav8").addClass("am-in");
  $("#jdxj").removeClass("am-collapsed");
  $("#jdxjjcsj").css("color", "#3399CC");
  $("#jcsjsbxq").css("color", "#3399CC");
  $("#qlsjOldlb").removeClass("li_a");

  $.ajaxSetup({
        data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
      });
      var devienameid = {{ devienameid | safe }};
      var systemid = {{ systemid | safe }};
      function delect_all() {
        $("#tbody_add").empty();
      }

      function add_save(){
        var parameter1 = $("#parameter1").val();
        var parameter2 = $("#parameter2").val();
        var locationid = $("#parts_sub_id option:selected").val();
        
        // var all_information = [];
        // $("#tbody_add tr").each(function(i){
        //   var one_information = {};
        //   var member_name = $(this).children('td').eq(1).text();
        //   var notes1 = $(this).children('td').eq(2).text();
        //   all_information.push({"member_name":member_name,"notes1":notes1});
        // })

        // // console.log(all_information);
        // // console.log(JSON.stringify(all_information));

        $.ajax({
          "url": "/JDXJ_JCSJ_SBXQ_DEVICE_ADDSAVE/",
          "data":{"systemid":systemid,"devienameid":devienameid,"locationid":locationid,"parameter1":parameter1,"parameter2":parameter2},
          "datatype": "json",
          "type": "post",
          "async": "false"
        }).success(function(data) {
          if(data.status == 1) {
            back_to();
          } else {
            AlertMSG(data.message)
          }
        }).error(function(data) {
          AlertMSG("保存失败！")
        });
      }
      function add_number(){
        var deviceName = $("#deviceName").html();         //设备类别
        var parameter1 = $("#parameter1").val();          //起始编号
        var parameter2 = $("#parameter2").val();          //终止编号
        var locationname = $("#parts_sub_id option:selected").html();
        var message = "";
        if  (parameter1 == ''){
          message = "请输入起始编号！";
          AlertMSG(message);
        } else if (parameter2 == ''){
          message = "请输入终止编号！";
          AlertMSG(message);
        } else if( parameter1*1>parameter2*1){
          message = "起始编号大于终止编号！";
          AlertMSG(message);
        }else if($("#button_number").val() == 1) {
            $("#button_number").val(2);
            $("#button_number").text("重新填写");
            $("#div_bxd input").attr("disabled", true);
            $("#div_bxd select").attr("disabled", true);
            $("#add_save").attr("disabled", false);
            $("#tbody_add").empty();
            var kk = 1;
            for(i = parameter1*1; i < parameter2*1+1; i++){
                var Device="";
                var Device = locationname+"-"+i+"#"+deviceName;
                var NO = i+"#";
            $("#tbody_add").append('<tr id=tbody_tr_' + kk + '><td>' + kk + '</td><td>' + NO + '</td><td>' + locationname + '</td><td>' + Device + '</td><td><div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs"><button class="am-btn am-btn-default am-btn-xs am-text-secondary button_click" onclick="delect_one(\'tbody_tr_' + kk + '\')">删除</button></div></div></td></tr>');
            kk = kk + 1;      
            }
          } else {
            $("#button_number").val(1);
            $("#button_number").text("生成编号");
            $("#div_bxd select").attr("disabled", false);
            $("#div_bxd input").attr("disabled", false);
            $("#add_save").attr("disabled", true);
            $("#parts_num").attr("disabled", true);
            $("#parts_note").attr("disabled", true);
            check();
          }

        }

      function delect_one(id) {
        $("#" + id).remove();
      }
      var message;

    
      function back_to() {
        window.history.go(-1);
      }


 
      function check(){
        $("#parameter1").attr("disabled",false);
        $("#parameter2").attr("disabled",false);
        var param_num = $("input:radio[name='param_num']:checked").val();
        for(var j=2;j>param_num;j--){
          $("#parameter"+j+"").attr("disabled",true);
        }
      }


      var AlertMSG = function(msg) {
        AMUI.dialog.alert({
          title: '错误提示',
          content: msg,
          onConfirm: function() {
            console.log('close');
          }
        });
      }
</script>

</body>

</html>